package com.guchenbo.datagen.common;

import cn.hutool.core.util.RandomUtil;
import org.apache.commons.lang3.RandomUtils;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
 * @author guchenbo
 * @date 2024/6/10
 */
public class PersonSupplier implements Supplier<Person> {

    private List<String> names = Arrays.asList("name1", "name2", "name3", "name4", "name5", "name6");
    private final Iterator<LocalDateTime> timestamps =
                    Stream.iterate(
                                                    LocalDateTime.of(2000, 1, 1, 1, 0),
                                                    time -> time.plusMinutes(5).plusSeconds(RandomUtil.randomInt(58) + 1))
                                    .iterator();
    @Override
    public Person get() {
        int idx = RandomUtils.nextInt(0, names.size());
        int age = RandomUtil.randomInt(30);
        LocalDateTime birthday=timestamps.next();
        return new Person(names.get(idx), age, birthday);
    }
}
